Patch from Christian Dywan to clean up selection data setting.
authorRichard Hult <richard@imendio.com>
Thu, 26 Jun 2008 13:01:40 +0000 (13:01 +0000)
committerRichard Hult <rhult@src.gnome.org>
Thu, 26 Jun 2008 13:01:40 +0000 (13:01 +0000)
2008-06-26  Richard Hult  <richard@imendio.com>

* gtk/gtkclipboard-quartz.c: (gtk_clipboard_wait_for_contents):
* gtk/gtkquartz.c:
(_gtk_quartz_get_selection_data_from_pasteboard),
(_gtk_quartz_set_selection_data_for_pasteboard): Patch from
Christian Dywan to clean up selection data setting.

svn path=/trunk/; revision=20690

ChangeLog
gtk/gtkclipboard-quartz.c
gtk/gtkquartz.c

index 8b3f21076821e972111eeea1e2c1ca5b6f1f3a48..0a7588b59473589c2505f9cb3f1d44cedab6307f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-06-26  Richard Hult  <richard@imendio.com>
+
+       * gtk/gtkclipboard-quartz.c: (gtk_clipboard_wait_for_contents):
+       * gtk/gtkquartz.c:
+       (_gtk_quartz_get_selection_data_from_pasteboard),
+       (_gtk_quartz_set_selection_data_for_pasteboard): Patch from
+       Christian Dywan to clean up selection data setting.
+
 2008-06-26  Richard Hult  <richard@imendio.com>
 
        * gtk/gtkdnd-quartz.c (gtk_drag_begin_internal): Don't use
index 45bd2f6f3a13c3f0128a8f5f599591d7d75898a5..6c209ee7280d40b18e6960074db3b73d0c04ae4d 100644 (file)
@@ -872,31 +872,29 @@ gtk_clipboard_wait_for_contents (GtkClipboard *clipboard,
   if (target == gdk_atom_intern_static_string ("TARGETS")) 
     {
       NSArray *types = [clipboard->pasteboard types];
-      int i, count;
+      int i, length;
       GList *atom_list, *l;
       GdkAtom *atoms;
 
-      count = [types count];
-      atom_list = _gtk_quartz_pasteboard_types_to_atom_list (types);
+      length = [types count] * sizeof (GdkAtom);
       
       selection_data = g_slice_new (GtkSelectionData);
       selection_data->selection = clipboard->selection;
       selection_data->target = target;
-      selection_data->type = GDK_SELECTION_TYPE_ATOM;
-      selection_data->format = 32;
-      selection_data->length = count * sizeof (GdkAtom);
 
-      atoms = g_malloc (selection_data->length + 1);
-      
+      atoms = g_malloc (length);
+
+      atom_list = _gtk_quartz_pasteboard_types_to_atom_list (types);
       for (l = atom_list, i = 0; l ; l = l->next, i++)
        atoms[i] = GDK_POINTER_TO_ATOM (l->data);
+      g_list_free (atom_list);
 
-      selection_data->data = (guchar *)atoms;
-      selection_data->data[selection_data->length] = '\0';
+      gtk_selection_data_set (selection_data,
+                              GDK_SELECTION_TYPE_ATOM, 32,
+                              (guchar *)atoms, length);
 
       [pool release];
 
-      g_list_free (atom_list);
       return selection_data;
     }
 
@@ -905,6 +903,7 @@ gtk_clipboard_wait_for_contents (GtkClipboard *clipboard,
                                                                   clipboard->selection);
 
   [pool release];
+
   return selection_data;
 }
 
index 9a6be3889c54e7ee577ca3233d74102170db39bd..bcecad4e36be5911bf5041b955a574457d7308de 100644 (file)
@@ -168,10 +168,9 @@ _gtk_quartz_get_selection_data_from_pasteboard (NSPasteboard *pasteboard,
        {
           const char *utf8_string = [s UTF8String];
 
-          selection_data->type = target;
-         selection_data->format = 8;
-         selection_data->length = strlen (utf8_string);
-         selection_data->data = (guchar*) g_strdup (utf8_string);
+          gtk_selection_data_set (selection_data,
+                                  target, 8,
+                                  (guchar *)utf8_string, strlen (utf8_string));
        }
     }
   else if (target == gdk_atom_intern_static_string ("application/x-color"))
@@ -243,12 +242,9 @@ _gtk_quartz_get_selection_data_from_pasteboard (NSPasteboard *pasteboard,
 
       if (data)
        {
-         selection_data->type = target;
-         selection_data->format = 8;
-         selection_data->length = [data length];
-         selection_data->data = g_malloc (selection_data->length + 1);
-         selection_data->data[selection_data->length] = '\0';
-         memcpy(selection_data->data, [data bytes], selection_data->length);
+         gtk_selection_data_set (selection_data,
+                                  target, 8,
+                                  [data bytes], [data length]);
        }
     }
 
@@ -256,21 +252,30 @@ _gtk_quartz_get_selection_data_from_pasteboard (NSPasteboard *pasteboard,
 }
 
 void
-_gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard *pasteboard,
+_gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard     *pasteboard,
                                               GtkSelectionData *selection_data)
 {
   NSString *type;
-  gchar *target = gdk_atom_name (selection_data->target);
+  gchar *target;
+  GdkDisplay *display;
+  gint format;
+  const guchar *data;
+  guint length;
+
+  target = gdk_atom_name (gtk_selection_data_get_target (selection_data));
+  display = gtk_selection_data_get_display (selection_data);
+  format = gtk_selection_data_get_format (selection_data);
+  data = gtk_selection_data_get_data (selection_data, &length);
 
   type = target_to_pasteboard_type (target);
   g_free (target);
 
   if ([type isEqualTo:NSStringPboardType]) 
-    [pasteboard setString:[NSString stringWithUTF8String:(const char *)selection_data->data]
+    [pasteboard setString:[NSString stringWithUTF8String:(const char *)data]
                   forType:type];
   else if ([type isEqualTo:NSColorPboardType])
     {
-      guint16 *color = (guint16 *)selection_data->data;
+      guint16 *color = (guint16 *)data;
       float red, green, blue, alpha;
       NSColor *nscolor;
 
@@ -278,7 +283,7 @@ _gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard *pasteboard,
       green = (float)color[1] / 0xffff;
       blue  = (float)color[2] / 0xffff;
       alpha = (float)color[3] / 0xffff;
-      
+
       nscolor = [NSColor colorWithDeviceRed:red green:green blue:blue alpha:alpha];
       [nscolor writeToPasteboard:pasteboard];
     }
@@ -287,11 +292,11 @@ _gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard *pasteboard,
       gchar **list = NULL;
       int count;
 
-      count = gdk_text_property_to_utf8_list_for_display (selection_data->display,
+      count = gdk_text_property_to_utf8_list_for_display (display,
                                                           gdk_atom_intern_static_string ("UTF8_STRING"),
-                                                          selection_data->format,
-                                                          selection_data->data,
-                                                          selection_data->length,
+                                                          format,
+                                                          data,
+                                                          length,
                                                           &list);
 
       if (count > 0)
@@ -310,8 +315,8 @@ _gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard *pasteboard,
       g_strfreev (list);
     }
   else
-    [pasteboard setData:[NSData dataWithBytesNoCopy:selection_data->data
-                                            length:selection_data->length
+    [pasteboard setData:[NSData dataWithBytesNoCopy:data
+                                            length:length
                                       freeWhenDone:NO]
                 forType:type];
 }